/**
 * Copyright (c) 2019 xstgongyi.org
 * All rights reserved.
 */
package org.xstgongyi.eduaid.common;

import java.util.HashMap;
import java.util.Map;

/**
 * 
 * Helper of controller layer, all methods must be static.
 * 
 * @author oldcrane<br/>
 * @created 2019-04-02
 */
public class ControllerHelper {

	private static final String KEY_CODE = "code";
	private static final String KEY_DATA = "data";
	private static final String KEY_MESSAGE = "message";

	public static Map<String, Object> successResponse(Object data) {
		return successResponse(data, null);
	}

	public static Map<String, Object> successResponse(Object data, String message) {
		Map<String, Object> map = new HashMap<>();
		map.put(KEY_CODE, "0"); // 0 for success
		map.put(KEY_DATA, data);
		map.put(KEY_MESSAGE, message);
		return map;
	}

	public static Map<String, Object> errorResponse(int code) {
		return errorResponse(code, null);
	}

	public static Map<String, Object> errorResponse(int code, String message) {
		Map<String, Object> map = new HashMap<>();
		map.put(KEY_CODE, code);
		map.put(KEY_MESSAGE, message);
		return map;
	}

}
